//
//  HomeViewController.swift
//  swiftDemo
//
//  Created by ChuanQi on 2019/5/5.
//  Copyright © 2019年 ChuanQi. All rights reserved.
//

import UIKit
import SnapKit
class HomeViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    let cell_identifier:String = "FirstCustomTableCell"
    var tableView = UITableView();
    var tableviewHeader:UIView!;
    var dataArray:NSMutableArray = NSMutableArray();
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "首页";
        self.createUI();
    }
    func createData(){
        for _ in 1...10 {
            var model:HomeModel = HomeModel();
            model.title = "开幕式";
            model.des   = "开幕式des";
            model.timer = "2020-02-02"
            model.ll    = "20"
            self.dataArray.add(model);
        }
        self.tableView.reloadData();
    }
    func createUI(){
        self.tableView = UITableView.init();
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.view.addSubview(tableView);
        self.tableView.tableFooterView = UIView.init();
        self.tableView.snp_makeConstraints { (make) in
            make.width.equalTo(self.view);
            make.height.equalTo(self.view);
        }
        self.tableView.register(HomeViewCell.classForCoder(), forCellReuseIdentifier:cell_identifier);
        self.createData();
    }
    
    // 每个分区行数（默认分区为一个）
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArray.count;
    }
    // 行高
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100.0
    }
    // cell
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:HomeViewCell = tableView.dequeueReusableCell(withIdentifier: cell_identifier, for: indexPath) as! HomeViewCell;
        cell.model = self.dataArray[indexPath.row] as? HomeModel;
        return cell
    }
    // cell点击事件处理
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
        case 0:
            let vc = UIViewController()
            self.navigationController?.pushViewController(vc, animated: true)
            break
        case 1:
            let vc = UIViewController()
            self.navigationController?.pushViewController(vc, animated: true)
            break
        default:
            
            break
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
